<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.iqoo.store.model.User" %>
<%
    User user = (User) session.getAttribute("user");
%>

<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="styles.css"> <!-- 引入CSS样式 -->
    <style>
        form label, form input, form button {
            display: block;
            margin-bottom: 10px;
        }
        /* 汉堡菜单样式 */
        .hamburger {
            display: none;
            cursor: pointer;
            padding: 10px;
        }

        .hamburger-line {
            width: 25px;
            height: 3px;
            background-color: #fff;
            margin: 5px 0;
            transition: all 0.3s ease;
            right: 0;
        }

        /* 响应式样式 */
        @media (max-width: 768px) {
            .hamburger {
                display: block;
                position: absolute;   /* 绝对定位 */
                right: 15px;          /* 距离右侧 15px */
            }

            .navbar-right {
                display: none;
                position: absolute;
                top: 60px;
                left: 0;
                width: 100%;
                background-color: #333;
                flex-direction: column;
                padding: 10px 0;
                box-shadow: 0 2px 5px rgba(0,0,0,0.1);
            }

            .navbar-right.active {
                display: flex;
            }

            .navbar-right a, .navbar-right span {
                padding: 10px 20px;
                border-bottom: 1px solid #333;
            }
        }
    </style>
</head>
<div class="navbar">
    <div class="navbar-left">
        <a href="index.jsp" class="logo">iQOO的小店</a>
    </div>
    <div class="navbar-right" id="navbarRight">
        <% if (user == null) { %>
        <a href="index.jsp">主页</a>
        <a href="register.jsp">注册</a>
        <a href="login.jsp">登录</a>
        <% } else { %>
        <span>欢迎, <%= user.getUsername() %>!</span>
        <% if(user.getRole() == 1) { %>
        <% } %>
        <a href="index.jsp">主页</a>
        <a href="goods.jsp">商品列表</a>
        <a href="cart.jsp">购物车</a>
        <% } %>
    </div>
    <div class="hamburger" onclick="toggleMenu()">
        <div class="hamburger-line"></div>
        <div class="hamburger-line"></div>
        <div class="hamburger-line"></div>
    </div>
</div>

<form action="login" method="post">
    <label>用户名:</label>
    <input type="text" name="username" required>
    <label>密码:</label>
    <input type="password" name="password" required>
    <button type="submit">登录</button>
</form>

<script>
    function toggleMenu() {
        const navbarRight = document.getElementById('navbarRight');
        navbarRight.classList.toggle('active');
    }
</script>